package com.example.musicbox.controller;


import com.example.musicbox.entity.MMusic;
import com.example.musicbox.entity.dto.PageAndSizeDto;
import com.example.musicbox.service.impl.MMusicServiceImpl;
import com.example.musicbox.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 帅哥是我
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/m-music")
public class MMusicController {

    @Resource
    private MMusicServiceImpl mMusicService;


    /**
     * @api {POST} /m-music/insertMusic 上传音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName insertMusic
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=Q1DVbG
     * @apiParam (请求体) {Number} mid
     * @apiParam (请求体) {String} mname
     * @apiParam (请求体) {String} mauthor
     * @apiParam (请求体) {Number} uid
     * @apiParam (请求体) {String} murl
     * @apiParam (请求体) {Number} msecond
     * @apiParam (请求体) {String} mstatus
     * @apiParam (请求体) {String} ispublish
     * @apiParam (请求体) {String} coverby
     * @apiParam (请求体) {String} mvurl
     * @apiParam (请求体) {Number} praisecount
     * @apiParam (请求体) {Number} praiseuserid
     * @apiParam (请求体) {String} praiseusername
     * @apiParam (请求体) {Number} listenuserid
     * @apiParam (请求体) {Number} listencount
     * @apiParam (请求体) {Number} downloadcount
     * @apiParam (请求体) {Number} needlevel
     * @apiParam (请求体) {Number} mType
     * @apiParam (请求体) {Object} uploadDate
     * @apiParamExample 请求体示例
     * {"msecond":9440,"listenuserid":789,"mid":8556,"mstatus":"WNMs","praisecount":2459,"mname":"DPlfGpPh","mauthor":"Nh5Zb","coverby":"wa","mType":1972,"uid":7205,"murl":"3FLmBhF","mvurl":"oAWvbF1","ispublish":"8pjrQ6","needlevel":5783,"praiseusername":"UJqKC2x7MG","listencount":1254,"downloadcount":8461,"praiseuserid":3761}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/insertMusic")
    public Result insertMusic(@RequestBody MMusic mMusic,@RequestHeader String token)
    {
        return mMusicService.insertMusic(mMusic,token);
    }


    /**
     * @api {POST} /m-music/deleteMusic 删除音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName deleteMusic
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=9
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     “id”:1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/deleteMusic")
    public Result deleteMusic(@RequestBody Map map,@RequestHeader String token)
    {
        Integer id = (Integer) map.get("id");
        return mMusicService.deleteMusic(id,token);
    }


    /**
     * @api {POST} /m-music/playMusic 播放音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName playMusic
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=8aILN38KTK
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     “id”:1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/playMusic")
    public Result playMusic(@RequestBody Map map,@RequestHeader String token)
    {
        Integer id = (Integer) map.get("id");
        return mMusicService.playMusic(id,token);
    }


    /**
     * @api {POST} /m-music/fontMusic 添加喜欢音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName fontMusic
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=RKI
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "id":1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/fontMusic")
    public Result fontMusic(@RequestBody Map map,@RequestHeader String token)
    {
        Integer id = (Integer) map.get("id");
        return mMusicService.fontMusic(id,token);
    }


    /**
     * @api {POST} /m-music/selectAll 查询音乐库中所有音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName selectAll
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "p":1,
     *     "s":1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectAll")
    public Result selectAll(@RequestBody Map map)
    {
        Integer p = (Integer) map.get("p");
        Integer s = (Integer) map.get("s");
        return mMusicService.selectAll(p,s);
    }


    /**
     * @api {POST} /m-music/selectByName 根据歌曲名称查询音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName selectByName
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "name":"dsfsd",
     *     "p":"1",
     *     "s":"10"
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectByName")
    public Result selectByName(@RequestBody Map map)
    {
        String name = (String) map.get("name");
        Integer p = (Integer) map.get("p");
        Integer s = (Integer) map.get("s");
        return mMusicService.selectByName(name,p,s);
    }


    /**
     * @api {POST} /m-music/selectByType 根据歌曲类型查询歌曲
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName selectByType
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "type":"1",
     *     "p":"1",
     *     "s":"10"
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectByType")
    public Result selectByType(@RequestBody Map map)
    {
        Integer type = (Integer) map.get("type");
        Integer p = (Integer) map.get("p");
        Integer s = (Integer) map.get("s");
        return mMusicService.selectByType(type,p,s);
    }


    /**
     * @api {POST} /m-music/downloadMusic 下载音乐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName downloadMusic
     * @apiParam (请求参数) {Number} mId
     * @apiParam (请求参数) {String} path
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * {
     *     “mId”:1,
     *     "path":"/szdfgsdg"
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/downloadMusic")
    public Result downloadMusic(@RequestBody Map map,@RequestHeader String token)
    {
        Integer mId = (Integer) map.get("mId");
        String path = (String) map.get("path");
        return mMusicService.downloadMusic(mId,path,token);
    }


    /**
     * @api {POST} /m-music/recommendMusic 为您推荐
     * @apiVersion 1.0.0
     * @apiGroup 音乐控制器
     * @apiName recommendMusic
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "p":1,
     *     "s":10
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/recommendMusic")
    public Result recommendMusic(@RequestBody PageAndSizeDto pageAndSizeDto)
    {

        return mMusicService.recommendMusic(pageAndSizeDto.getP(),pageAndSizeDto.getS());
    }
}

